#include "GDisk.h"

namespace GMath
{

	GDisk::GDisk()
	{
		Radius = 1.0f;
		Center = GVector3::Zero;
		Normal = GVector3::UnitZ;
	}

	GDisk::GDisk(const GVector3& TheCenter, const GVector3& TheNormal, float TheRadius)
	{
		Create(TheCenter, TheNormal, TheRadius);
	}

	void GDisk::Create(const GVector3& TheCenter, const GVector3& TheNormal, float TheRadius)
	{
		Radius = TheRadius;
		Center = TheCenter;
		Normal = TheNormal;
	}

	float GDisk::Area() const
	{
		return G_PI * Radius * Radius;
	}

	float GDisk::Circumference() const
	{
		return G_PI * Radius * 2.0f;
	}

	GHalfSpaceResult GDisk::HalfSpace(const GVector3& Point)
	{
		GVector3 Vec = Point - Center;
		float SignedDist = Normal.Dot(Vec);
	
		if (SignedDist < -G_ZERO_TRESHOLD )
		{
			return G_HSR_NEGATIVE;
		}
		else if (SignedDist > G_ZERO_TRESHOLD)
		{
			return G_HSR_POSITIVE;
		}
	
		return G_HSR_ON_PLANE;
	}

	void GDisk::Convert(OUTPUT GPlane& Output, const GDisk& Disk)
	{
		Output.Create(Disk.Center, Disk.Normal);
	}

}